<?php
// +----------------------------------------------------------------------
// | Yotaku shop
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.yotaku.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Creatint <creatint@163.com> <http://creatint.yotaku.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Think\Controller;
class BaseController extends Controller {
    /**
     * @describe 父类 初始化方法 父级construct自动调用
     * @author Creatint
     */
    public function _initialize(){
        //TODO: 父级控制器 判断用户身份
        // 读取数据库中的配置
        $config =   (1 == C('STORAGE_CACHE'))?S('DB_CONFIG_DATA') :null ;
        if(!$config){
            $config =   api('Config/getConfigLists',array('status'=>1));
            if(1 == $config['STORAGE_CACHE']) S('DB_CONFIG_DATA',$config);
        }
        C($config); //添加配置.




        $this->assign('__MENU__', $this->getMenus());
    }


    final public function getMenus($controller = CONTROLLER_NAME){
        $menus  =   (1 == C('STORAGE_CACHE'))?session('ADMIN_MENU_LIST.' . $controller):array();
        if(!empty($menus)){
            return $menus;
        }

        $Menu   =   D('Menu');

        //获取主菜单
        $map             = array();
        $map['pid']     =   0;
        $map['hide']    =   0;
        $map['status']  =   1;
        $menus['main']  =   $Menu->where($map)->order("`sort` asc")->select();

        //获取子菜单


        return $menus;
    }
}